package com.tjhk.common.utils.web;

import java.io.Serializable;

/**
 * @author ：little grape
 * @description：TODO
 * @date ：2023/7/19 22:13
 */
public class Result<T> implements Serializable {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 提示信息
     */
    private String message;
    /**
     * 数据
     */
    private T data;

    private Result() {

    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static<T> Result<T> success(int code, String message, T data) {
        Result<T> resultVO = new Result<>();
        resultVO.setData(data);
        resultVO.setCode(code);
        resultVO.setMessage(message);
        return resultVO;
    }

    public static <T> Result<T> success(T data) {
        Result<T> resultVO = new Result<>();
        resultVO.setData(data);
        resultVO.setCode(HttpStatus.OK.value());
        resultVO.setMessage("请求成功");
        return resultVO;
    }

    public static Result<String> success() {
        Result<String> resultVO = new Result<>();
        resultVO.setCode(HttpStatus.OK.value());
        resultVO.setMessage(HttpStatus.OK.message());
        return resultVO;
    }

    public static Result<String> failed(int code, String message) {
        Result<String> resultVO = new Result<>();
        resultVO.setCode(code);
        resultVO.setMessage(message);
        return resultVO;
    }

    public static Result<String> failed() {
        Result<String> resultVO = new Result<>();
        resultVO.setCode(HttpStatus.BAD_REQUEST.value());
        resultVO.setMessage(HttpStatus.BAD_REQUEST.message());
        return resultVO;
    }

    public static Result<String> failed(String message) {
        Result<String> resultVO = new Result<>();
        resultVO.setCode(HttpStatus.BAD_REQUEST.value());
        resultVO.setMessage(message);
        return resultVO;
    }

}
